<template>
	<view class="pay">
		<view class="payorder">
			<view class="payNumber">
				订单号:{{outTradeNo}}
			</view>
			<view class="payPrice">
				<text>¥</text>{{totalAmount}}
			</view>
		</view>
		<view class="payType">
			<view class="payTypeTitle">
				请选择支付方式
			</view>
			<radio-group @change="radioChange">
				<view class="payTypeItem">
					<view class="payTypeItemLeft">
						<image src="../../static/images/alipay.png" class="payicon"></image>支付宝支付
					</view>
					<radio color="#01c2fa" value="1" checked=""></radio>
				</view>
				<view class="payTypeItem">
					<view class="payTypeItemLeft">
						<image src="../../static/images/wxpay.png" class="payicon"></image>微信支付
					</view>
					<radio color="#01c2fa" value="2"></radio>
				</view>
			</radio-group>

		</view>
		<view class="payButton" @click="pay">
			确定支付
		</view>

		<!-- 添加支付表单区域 -->
		<div ref="divForm" id="divform" v-html="payForm"></div>
	</view>

</template>

<script>
	import {
		aliPay
	} from '@/request/app.js'
	export default {
		data() {
			return {
				paytype: 1,
				payForm: '',
				totalAmount: 0,
				outTradeNo: '',
			}
		},
		onLoad(option) {
			console.log(option);
			this.totalAmount = option.money
			this.outTradeNo = option.num
		},
		methods: {
			//封装一个确定支付的方法
			pay() {
				//确认支付接口
				aliPay({
						outTradeNo: this.outTradeNo,
						totalAmount: this.totalAmount,
						type: 1
					})
					.then(res => {
						// //把支付的表单渲染到视图中，然后触发提交按钮
						this.payForm = res.data.list
						this.$nextTick(() => {
							document.forms[0].submit()
						})
					})
			}
		}
	}
</script>

<style>
	.payicon {
		width: 30rpx;
		height: 30rpx;
		margin-right: 20rpx;
	}

	.payButton {
		height: 80rpx;
		width: 624rpx;
		position: fixed;
		bottom: 120rpx;
		background: #0bbaef;
		left: 50%;
		margin-left: -312rpx;
		text-align: center;
		line-height: 80rpx;
		color: #fff;
		font-size: 28rpx;
		border-radius: 80rpx;
	}


	.payType {
		width: 650rpx;
		margin: 58rpx auto 0;
	}

	.payType .payTypeTitle {
		font-size: 28rpx;
		line-height: 55rpx;
	}

	.payType .payTypeItem {
		display: flex;
		justify-content: space-between;
		height: 76rpx;
		align-items: center;
	}

	.payTypeItemLeft {
		font-size: 28rpx;
		display: flex;
		align-items: center;
	}

	.payType .payTypeItem i {
		font-size: 32rpx;
		margin-right: 20rpx;
		display: block;
	}

	.payType .payTypeItem radio {
		transform: scale(0.7);
	}

	/* switch */


	.payNumber {
		font-size: 24rpx;
		color: #999;
		text-align: center;
		padding-top: 54rpx;
	}

	.payPrice {
		font-size: 70rpx;
		color: #000;
		height: 120rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.payPrice text {
		font-size: 28rpx;
	}

	.payTime {
		font-size: 24rpx;
		color: #999;
		line-height: 56rpx;
		text-align: center;
	}
</style>
